package com.zy.explore.strategy.interfaces.assembler;

import com.zy.explore.strategy.application.service.VipStrategyService;
import com.zy.explore.strategy.infrastructure.strategy.CalcStrategy;
import com.zy.explore.strategy.infrastructure.strategy.CalcStrategyFactory;
import com.zy.explore.strategy.interfaces.frm.VipCostFrm;
import com.zy.explore.strategy.interfaces.vo.ResultVO;
import com.zy.explore.strategy.interfaces.vo.VipRealCostVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * description 转换器
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2021年07月03日 01:34
 */
@Component
public class VipStrategyAssembler {

    @Resource
    private VipStrategyService vipStrategyService;

    /**
     * 计算会员花费
     *
     * @param frm 请求参数对象
     * @return {@link ResultVO<VipRealCostVO>}
     */
    public VipRealCostVO calcCosts(VipCostFrm frm) {
        return vipStrategyService.calcCosts(frm);
    }

    /**
     * 使用策略模式+简单工厂计算会员实际花费
     *
     * @param frm 请求参数
     * @return {@link VipRealCostVO}
     */
    public VipRealCostVO calcCostsWithStrategy(VipCostFrm frm) {
        CalcStrategy calcStrategy = CalcStrategyFactory.getInstance().get(frm.getVipType());
        return calcStrategy.calc(new BigDecimal(frm.getCosts()));
    }
}
